package com.itheima.controller;

import com.itheima.domain.FlashPromotion;
import com.itheima.manager.SmsFlashPromotionManager;
import com.itheima.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/flash")
public class SmsFlashPromotionController {

    @Autowired
    SmsFlashPromotionManager smsFlashPromotionManager;
    //根据活动名称分页查询
    @GetMapping("/list")
    public Result flashByPage(
            @RequestParam(required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(required = false,defaultValue = "5")Integer pageSize,
            String keyword) throws Exception {
        return smsFlashPromotionManager.flashByPage(pageNum,pageSize,keyword);
    }

    //添加活动
    @PostMapping("/create")
    public Result create(@RequestBody FlashPromotion flashPromotion){
        return smsFlashPromotionManager.create(flashPromotion);
    }

    //删除活动
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        return smsFlashPromotionManager.delete(id);
    }

    //修改上下线状态
    @PostMapping("/update/status/{id}")
    public Result updateStatus(
            @PathVariable Integer id,
            @RequestParam(required = false) Integer status){
        return smsFlashPromotionManager.updateStatus(id,status);
    }
    //编辑活动
    @PostMapping("/update/{id}")
    public Result updateById(
            @PathVariable Integer id,
            @RequestBody FlashPromotion flashPromotion){
        return smsFlashPromotionManager.updateById(id,flashPromotion);
    }
    //获取活动详情
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        return smsFlashPromotionManager.selectById(id);
    }


}
